# JavaScript Booleans

« Previous
Next Chapter »

A JavaScript Boolean represents one of two values: true or false.

## Boolean Values

Very often, in programming, you will need a data type that can only have one of two values, like

- YES / NO
- ON / OFF
- TRUE / FALSE

For this, JavaScript has a Boolean data type. It can only take the values true or false.

## The Boolean() Function

You can use the Boolean() function to find out if an expression (or a variable) is true:

## Example

Boolean(10 > 9) // returns true
Try it Yourself »

Or even easier:

## Example

(10 > 9) // also returns true
10 > 9 // also returns true
Try it Yourself »

## Comparisons and Conditions

The chapter JS comparisons gives a full overview of comparison operators.

The chapter JS conditions gives a full overview of conditional statements.

Here are some examples:

Operator | Description | Example
--- | --- | ---
== | equal to | if (day == "Monday")
> | greater than | if (salary > 9000)
< | less than | if (age < 18)

| The Boolean value of an expression is the fundament for JavaScript comparisons and conditions.

## Everything With a Real Value is True

## Examples

100
3.14
-15
"Hello"
"false"
7 + 1 + 3.14
5 < 6
Try it Yourself »

## Everything Without a Real Value is False

The Boolean value of 0 (zero) is false:
var x = 0;
Boolean(x); // returns false
Try it Yourself »
The Boolean value of -0 (minus zero) is false:
var x = -0;
Boolean(x); // returns false
Try it Yourself »
The Boolean value of "" (empty string) is false:
var x = "";
Boolean(x); // returns false
Try it Yourself »
The Boolean value of undefined is false:
var x;
Boolean(x); // returns false
Try it Yourself »
The Boolean value of null is false:
var x = null;
Boolean(x); // returns false
Try it Yourself »
The Boolean value of false is (you guessed it) false:
var x = false;
Boolean(x); // returns false
Try it Yourself »
The Boolean value of NaN is false:
var x = 10 / "H";
Boolean(x); // returns false
Try it Yourself »

## Boolean Properties and Methods

Primitive values, like true and false, cannot have properties or methods (because they are not objects).

But with JavaScript, methods and properties are also available to primitive values, because JavaScript treats primitive values as objects when executing methods and properties.

## Complete Boolean Reference

For a complete reference, go to our Complete JavaScript Boolean Reference.

The reference contains descriptions and examples of all Boolean properties and methods.

« Previous
Next Chapter »

### WEB HOSTING

UK Reseller Hosting

### WEB BUILDING

FREE Website BUILDER Free HTML5 Templates

### W3SCHOOLS EXAMS

HTML, CSS, JavaScript, PHP, jQuery, XML, and ASP Certifications

### SHARE THIS PAGE

### Color Picker

### HTML/CSS

HTML Tutorial HTML5 Tutorial CSS Tutorial CSS3 Tutorial Bootstrap Tutorial

### JavaScript

JavaScript Tutorial jQuery Tutorial jQuery Mobile Tutorial AngularJS Tutorial AJAX Tutorial JSON Tutorial

### Graphics

Canvas Tutorial SVG Tutorial Google Maps Tutorial

### Server Side

SQL Tutorial PHP Tutorial ASP Tutorial ASP.NET Tutorial VBScript Tutorial AppML Tutorial

### Web

Web Building Web Statistics Web Certification

### XML

XML Tutorial DTD Tutorial Schema Tutorial XML DOM Tutorial XPath Tutorial XSLT Tutorial XQuery Tutorial XSL-FO Tutorial RSS Tutorial WSDL Tutorial

### HTML/CSS

HTML Tag Reference HTML Event Reference HTML Color Reference CSS 1,2,3 Reference Bootstrap Reference

### JavaScript

JavaScript Reference HTML DOM Reference jQuery Reference jQuery Mobile Reference Google Maps Reference

### Server Side

PHP Reference SQL Reference ASP Reference VBScript Reference Razor Reference ASP.NET Reference

### XML

XML DOM Reference XSLT Reference XSL-FO Reference XPath Reference XQuery Reference Schema Reference RSS Reference SVG Reference

### HTML Charsets

HTML Character Sets HTML ASCII HTML ANSI HTML Windows-1252 HTML ISO-8859-1 HTML Symbols HTML UTF-8

### HTML/CSS

HTML Examples CSS Examples

### Browser Scripting

JavaScript Examples HTML DOM Examples jQuery Examples jQuery Mobile Examples AngularJS Examples AJAX Examples

### Server Scripting

PHP Examples ASP Examples VBScript Examples Razor Examples .NET Examples

### XML Languages

XML Examples DTD Examples XML DOM Examples XSL Examples XSLT Examples XPath Examples XQuery Examples Schema Examples RSS Examples SVG Examples